# Makefile for compiling Nameservice

# Some paths
UTILSDIR=../../../utils
BASEDIR=../..
PROTOCOLDIR=../../protocol
GIMNETAP_COMMON_LIBDIR=../../commonlib
GIMNETAP_SERVICES_COMMON_LIBDIR=../common

# Some tools
CC=gcc

CFLAGS=-O2 -g3 -Wall -I. -I$(BASEDIR) -I$(PROTOCOLDIR) -I$(UTILSDIR)	\
-I$(BASEDIR)/services/common -I$(GIMNETAP_COMMON_LIBDIR) -DLINUX_OS		\
-DUSE_SELECT_IO $(CE)

LD=gcc
LDFLAGS=
LIBS=-lpthread -lrt -lssl -lcrypto

# Base Sources
SRCSBASE=$(UTILSDIR)/ownutils.c $(UTILSDIR)/owndebug.c	$(UTILSDIR)/crc16.c \
				 $(PROTOCOLDIR)/protocolID.c 

# CommonLib
include $(GIMNETAP_COMMON_LIBDIR)/GIMnetAP-common.Makefile

# All sources
SRCS=$(SRCSBASE) $(GIMNETAP_COMMON_SRCS)

# Construct lists of CPP and C objects
OBJS=$(SRCS:.c=.o)

# Define COMPILE and LINK commands
COMPILE=$(CC) $(CFLAGS) -c
LINK=$(LD) $(LDFLAGS) 

all: multicast multicast_test

####### Multicast target
MULTICAST_OBJECTS=$(OBJS) $(BASEDIR)/services/common/apservicebase.o	\
multicast.o multicastcore.o multicasttable.o
multicast: $(MULTICAST_OBJECTS)
	@$(LINK) -o $@ $(MULTICAST_OBJECTS) $(LIBS)
	@echo "      [LD] $@"

####### Multicast testclient
MULTICAST_TEST_OBJECTS=$(OBJS) multicast_test.o
multicast_test: $(MULTICAST_TEST_OBJECTS)
	@$(LINK) -o $@ $(MULTICAST_TEST_OBJECTS) $(LIBS) -lcurses
	@echo "      [LD] $@"

.PHONY: common_clean
common_clean:
	@rm -f $(BASEDIR)/services/common/*.o
	@echo "      [CLEAN] common"

clean: common_clean
	@rm -f $(OBJS) *.o multicast multicast_test
	@echo "      [CLEAN] multicast"

# Default compile rule.
%.o:	%.c
	@$(COMPILE) -o $@ $<
	@echo "      [CC] $<"

.PHONY: all clean depend testclients
